﻿
function Alert(text, type, time) {
    ShowTips(text, type, null, true, time);
}

function ShowTips(text, type, callback, showmask, time) {
    var layer = $('.tip_layer');
    if (layer.length < 1) {
        layer = $('<div></div>').appendTo($('body')).addClass('tip_layer');
        $('<div></div>').appendTo(layer).addClass('tip_left');
        $('<div></div>').appendTo(layer).addClass('tip_content');
        $('<div></div>').appendTo(layer).addClass('tip_right');
    }
    if (typeof type != 'undefined') {
        layer.find('.tip_left').removeClass('t1').removeClass('t2').addClass('t' + type);
    }
    layer.find('.tip_content').html(text);
    var scrollTop = top.document.documentElement.scrollTop + top.document.body.scrollTop;
    layer.show().css({
        top: ((document.documentElement.clientHeight / 2 - layer.height() / 2) + scrollTop),
        left: ($('body').width() / 2) - (layer.width() / 2)
    });

    if (typeof showmask == 'undefined' || !showmask) showmask = false;
    else showmask = true;
    if (showmask) ShowMask(document);
    
    if (time == false) return;
    if (typeof time == 'undefined')
         time = 1;
     setTimeout(function () {
         layer.hide();
         if (showmask) HideMask(document);
         if (typeof callback == 'function') {
             callback();
         }
     }, time * 1000
		);
};

function HideTips() {
    $('.tip_layer').hide();
    HideMask(document);
};

function ShowMask(doc) {
    if (typeof doc == 'undefined') doc = document;
    var body = doc.body;
    var mask = $(body).find('#DivMask');
    var h = doc.documentElement.scrollHeight;
    if (h < doc.documentElement.clientHeight) h = doc.documentElement.clientHeight;
    if (mask.length < 1) {
        mask = $("<div></div>").appendTo($(body))
					.attr("id", "DivMask")
					.css({ position: "absolute",
					    background: "#ccc",
					    top: "0px",
					    left: "0px",
					    zIndex: "2",
					    width: "100%",
					    height: h,
					    filter: 'alpha(Opacity=50)',
					    opacity: '0.3'
					});
        $("<IFRAME style=\"width:100%;height:100%;filter:alpha(opacity=0);-moz-opacity:0\"></IFRAME>").appendTo(mask);
    }
    mask.show();
};

function HideMask(body) {
    if (typeof body == 'undefined') body = document;
    $(body.body).find('#DivMask').hide();
};
